<!DOCTYPE html>
<html>
<head>
    <title>日志</title>
    {% include 'system/common/header.html' %}
</head>
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
                <li class="layui-this">登录日志</li>
                <li>操作日志</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <table style="margin-top: 10px;" id="log-login-table" lay-filter="log-login-table"></table>
                </div>
                <div class="layui-tab-item">
                    <table style="margin-top: 10px;" id="log-operate-table" lay-filter="log-operate-table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>


<script type="text/html" id="log-createTime">
    {{ '  {{layui.util.toDateString(d.create_time,  "yyyy-MM-dd HH:mm:ss")}' |safe }}}
</script>
<script type="text/html" id="log-status">
    {{ '{{#if (d.status == 1) { }}
    <span style="color: green">成功</span>
    {{# }else if(d.status == 0){ }}
    <span style="color: red">失败</span>
    {{# } }}'|safe }}
</script>
{% include 'system/common/footer.html' %}
<script>
    layui.use(['table', 'form', 'jquery', 'element', 'util'], function () {
        let table = layui.table
        let form = layui.form

        let MODULE_PATH = '/system/log/'

        let loginCols = [
            [
                {title: '编号', field: 'id', align: 'center', width: 80},
                {title: '用户编号', field: 'user_id', align: 'center', width: 100},
                {title: '请求ID', field: 'request_id', align: 'center', width: 150},
                {title: '请求参数', field: 'form', align: 'center', width: 150},
                {title: '浏览器', field: 'browser', align: 'center', width: 150},
                {title: '系统', field: 'system', align: 'center', width: 100},
                {title: '国家', field: 'country', align: 'center', width: 100},
                {title: '大区', field: 'region', align: 'center', width: 100},
                {title: '省份', field: 'province', align: 'center', width: 100},
                {title: '城市', field: 'city', align: 'center', width: 100},
                {title: '运营商', field: 'isp', align: 'center', width: 100},
                {title: '访问状态', templet: '#log-status', align: 'center', width: 100},
                {title: '创建时间', field: 'create_time', templet: '#log-createTime', align: 'center', width: 160}
            ]
        ]
        
        let operateCols = [
            [
                {title: '编号', field: 'id', align: 'center', width: 80},
                {title: '请求方式', field: 'method', align: 'center', width: 100},
                {title: '用户编号', field: 'user_id', align: 'center', width: 100},
                {title: '请求地址', field: 'url', align: 'center', width: 150},
                {title: '请求ID', field: 'request_id', align: 'center', width: 150},
                {title: '路由描述', field: 'summary', align: 'center', width: 150},
                {title: '请求参数', field: 'params', align: 'center', width: 150},
                {title: '耗时(秒)', field: 'cost_time', align: 'center', width: 100},
                {title: '浏览器', field: 'browser', align: 'center', width: 150},
                {title: '系统', field: 'system', align: 'center', width: 100},
                {title: '标签', field: 'tags', align: 'center', width: 100},
                {title: '路由名称', field: 'route_name', align: 'center', width: 150},
                {title: '状态', field: 'status', align: 'center', width: 80},
                {title: '内容长度', field: 'content_length', align: 'center', width: 100},
                {title: '国家', field: 'country', align: 'center', width: 100},
                {title: '大区', field: 'region', align: 'center', width: 100},
                {title: '省份', field: 'province', align: 'center', width: 100},
                {title: '城市', field: 'city', align: 'center', width: 100},
                {title: '运营商', field: 'isp', align: 'center', width: 100},
                {title: '创建时间', field: 'create_time', templet: '#log-createTime', align: 'center', width: 160}
            ]
        ]

        table.render({
            elem: '#log-operate-table',
            url: MODULE_PATH + 'operateLog',
            page: true,
            cols: operateCols,
            skin: 'line',
            toolbar: false
        })

        table.render({
            elem: '#log-login-table',
            url: MODULE_PATH + 'loginLog',
            page: true,
            cols: loginCols,
            skin: 'line',
            toolbar: false
        })

        form.on('submit(dict-type-query)', function (data) {
            table.reload('dict-type-table', {where: data.field})
            return false
        })

        table.on('tool(log-operate-table)', function (obj) {
            if (obj.event === 'details') {
                window.info(obj)
            }
        })

        table.on('tool(log-login-table)', function (obj) {
            if (obj.event === 'details') {
                window.info(obj)
            }
        })

        window.info = function (obj) {
            layer.open({
                type: 2,
                title: '详细信息',
                shade: 0,
                area: ['400px', '400px'],
                content: MODULE_PATH + 'info',
                success: function (layero) {
                    let iframeWin = window[layero.find('iframe')[0]['name']]
                    iframeWin.show(obj.data)
                }
            })
        }
    })
</script>
</html>